package lab03.test14;


import java.sql.*;

public class Test {
    public static void main(String[] args) {
        //3+1
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;

        String sql="select*from t_userinfo";

        try {
            Class.forName("com.mysql.jdbc.Driver");

            /**数据库链接字符串
             * 数据库用户名
             * 数据库密码
             */
        connection= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test",
                "root",
                "12345678"
        );

        statement=connection.createStatement();
        statement.execute(sql);

        resultSet=statement.executeQuery(sql);
        while (resultSet.next()){

            System.out.println(resultSet.getString(1));
            System.out.println(resultSet.getString(2));
            System.out.println(resultSet.getString(3));
            System.out.println(resultSet.getString(4));
        }



        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {

            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }
}
